using ASP;
using HoWave.Common;
using HoWave.Web;
using HoWave.Web.Shop.Member;
using System;
using System.Data;
using System.Web.Profile;
using System.Web.SessionState;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
public class Shop_Manage_shop_setup : Member, IRequiresSessionState
{
	protected TextBox TxtShopName;
	protected DropDownList DropShopClass;
	protected HiddenField hfSecUrl;
	protected TextBox txt_SecUrl;
	protected HtmlGenericControl secUrlFail;
	protected HtmlTableRow tr_SecUrl;
	protected RadioButtonList ShopStatus;
	protected TextBox TxtOperatorItem;
	protected TextBox TxtShopIntro;
	protected FileUpload FileUpload1;
	protected Image ImageURL;
	protected FileUpload FileUpload2;
	protected Image ImageBanner;
	protected TextBox TxtShopAnnouncement;
	protected Button ButSaveBaseShop;
	public int ShopID = 1;
	public int ShopTemSelID = 0;
	public string ShopInstallDir = "/";
	protected DefaultProfile Profile
	{
		get
		{
			return (DefaultProfile)this.Context.Profile;
		}
	}
	protected global_asax ApplicationInstance
	{
		get
		{
			return (global_asax)this.Context.ApplicationInstance;
		}
	}
	protected void Page_Load(object sender, EventArgs e)
	{
		this.ShopID = base.user.ShopID;
		this.ShopInstallDir = this.config["InstallDir"].ToString();
		if (!base.IsPostBack)
		{
			this.BandShopClass();
			this.BandBaseShop();
		}
		this.FileUpload1.Attributes.Add("onchange", "return viewimg(this)");
		this.FileUpload2.Attributes.Add("onchange", "return viewimg2(this)");
	}
	protected void BandBaseShop()
	{
		Shop_Shop shop_Shop = new Shop_Shop(this.conn);
		DataTable shopByShopID = shop_Shop.GetShopByShopID(this.ShopID);
		if (shopByShopID.Rows.Count <= 0)
		{
			this.WriteErrMsg("友情提示", Language.GetMemberMsg("Common/NoShop", new string[0]), "../Member/Shop_OpenShop.aspx");
		}
		if (shopByShopID.Rows[0]["ShopStatus"] != DBNull.Value && shopByShopID.Rows[0]["ShopStatus"] != null)
		{
			string a = shopByShopID.Rows[0]["ShopStatus"].ToString();
			if (a == "1")
			{
				this.ShopStatus.Items[0].Selected = true;
			}
			else
			{
				if (a == "0")
				{
					this.ShopStatus.Items[1].Selected = true;
				}
				else
				{
					if (a == "-1")
					{
						this.WriteErrMsg("", Language.Get("Shop/ShopStatus/Close"), "../Member/MyShop.aspx");
					}
				}
			}
		}
		this.TxtShopName.Text = shopByShopID.Rows[0]["ShopName"].ToString();
		this.DropShopClass.SelectedIndex = this.DropShopClass.Items.IndexOf(this.DropShopClass.Items.FindByValue(shopByShopID.Rows[0]["ShopCategoryID"].ToString()));
		this.TxtOperatorItem.Text = shopByShopID.Rows[0]["ShopOperatorItem"].ToString();
		if (shopByShopID.Rows[0]["ShopImageURL"].ToString() != string.Empty)
		{
			this.ImageURL.ImageUrl = shopByShopID.Rows[0]["ShopImageURL"].ToString();
		}
		if (shopByShopID.Rows[0]["ShopAdUrl"].ToString() != string.Empty)
		{
			this.ImageBanner.ImageUrl = shopByShopID.Rows[0]["ShopAdUrl"].ToString();
		}
		this.TxtShopIntro.Text = shopByShopID.Rows[0]["ShopIntro"].ToString();
		this.TxtShopAnnouncement.Text = shopByShopID.Rows[0]["ShopAnnouncement"].ToString();
		if (shop_Shop.IsSecUrl(this.ShopID))
		{
			this.tr_SecUrl.Attributes.Add("style", "");
			this.txt_SecUrl.Enabled = true;
			this.txt_SecUrl.Text = shopByShopID.Rows[0]["SecUrl"].ToString();
			this.hfSecUrl.Value = shopByShopID.Rows[0]["SecUrl"].ToString();
		}
		else
		{
			this.tr_SecUrl.Attributes.Add("style", "display:none;");
			this.txt_SecUrl.Enabled = false;
			this.txt_SecUrl.Text = "";
			this.hfSecUrl.Value = "";
		}
	}
	protected void BandShopClass()
	{
		int parentID = 0;
		Shop_Class shop_Class = new Shop_Class(this.conn);
		DataTable allChildClassByParnetID = shop_Class.GetAllChildClassByParnetID(parentID);
		foreach (DataRow dataRow in allChildClassByParnetID.Rows)
		{
			string text = dataRow["ClassName"].ToString();
			string value = dataRow["ClassID"].ToString();
			if (text != "")
			{
				if (!(text == "服务商品") && !(text == "创美商品"))
				{
					ListItem item = new ListItem(text, value);
					this.DropShopClass.Items.Add(item);
				}
			}
		}
		this.DropShopClass.DataBind();
	}
	protected void ButSaveBaseShop_Click(object sender, EventArgs e)
	{
		if (this.TxtShopName.Text == "" || string.IsNullOrEmpty(this.TxtShopName.Text))
		{
			this.WriteErrMsg("", "店铺名称不能为空！", "");
		}
		else
		{
			string text = this.txt_SecUrl.Text.Trim();
			if (!string.IsNullOrEmpty(text))
			{
				if (!string.IsNullOrEmpty(this.hfSecUrl.Value))
				{
					if (this.hfSecUrl.Value.Trim() != text)
					{
						IDbDataParameter dbDataParameter = this.conn.CreateParameter("@SecUrl", DbType.String, text);
						int num = this.conn.ExecuteCount("select COUNT(SecUrl) from dbo.HLShop_Shop where  SecUrl=@SecUrl", new IDbDataParameter[]
						{
							dbDataParameter
						});
						if (num > 0)
						{
							this.secUrlFail.Visible = true;
							return;
						}
					}
				}
			}
			int shopStatus = Convert.ToInt32(this.ShopStatus.SelectedValue);
			string shopAddress = "";
			int shopIdentify = 0;
			string shopImageUrl;
			if (this.FileUpload1.PostedFile.FileName != "")
			{
				shopImageUrl = this.UploadPhoto("Logo", this.FileUpload1, 100, 100);
			}
			else
			{
				shopImageUrl = "";
			}
			string shopAdUrl;
			if (this.FileUpload2.PostedFile.FileName != "")
			{
				shopAdUrl = this.UploadPhoto("Banner", this.FileUpload2, 80, 600);
			}
			else
			{
				shopAdUrl = "";
			}
			string text2 = this.TxtShopAnnouncement.Text;
			string text3 = this.TxtShopIntro.Text;
			text2 = Text.wipeScript(text2);
			text3 = Text.wipeScript(text3);
			Shop_Shop shop_Shop = new Shop_Shop(this.conn);
			ShopGroupBll shopGroupBll = new ShopGroupBll(this.conn);
			DataTable shopByShopID = shop_Shop.GetShopByShopID(this.ShopID);
			if (shopByShopID.Rows.Count < 0)
			{
				this.WriteErrMsg("", Language.Get("Common/NotData"), "");
			}
			string groupPowerById = shopGroupBll.GetGroupPowerById(Convert.ToInt32(shopByShopID.Rows[0]["ShopGroupID"]));
			if (shopGroupBll.CheckGroupPower(groupPowerById, "needcheck"))
			{
				shopIdentify = Convert.ToInt32(shopByShopID.Rows[0]["ShopIdentify"]);
			}
			bool flag = shop_Shop.UpdateBaseShop(this.TxtShopName.Text, text2, text3, Convert.ToInt32(this.DropShopClass.SelectedValue), shopImageUrl, shopAdUrl, this.TxtOperatorItem.Text, this.ShopID, shopAddress, shopStatus, shopIdentify, text);
			if (flag)
			{
				this.WriteSuccessMsg("", Language.GetMemberMsg("Common/EditSuccess", new string[0]), "shop_setup.aspx?rnd=" + DateTime.Now.ToString("yyyyMMddhhmmss"));
			}
			else
			{
				this.WriteErrMsg("", Language.GetMemberMsg("Common/EditFail", new string[]
				{
					"0"
				}), "");
			}
			this.BandBaseShop();
		}
	}
	protected string UploadPhoto(string ImageType, FileUpload UploadPostFile, int Width, int Height)
	{
		string result;
		if (!UploadPostFile.HasFile)
		{
			result = "";
		}
		else
		{
			string newFileName = string.Concat(new object[]
			{
				"Shop_",
				this.ShopID,
				"_",
				ImageType
			});
			int num = Text.ToInt32(base.user.GetGroupPower("AllowUploadSize"));
			num *= 1024;
			if (UploadPostFile.PostedFile.ContentLength > num)
			{
				this.WriteErrMsg("", Language.Get("Shop/Product/UpLoadTypeLarget", num.ToString()), "");
			}
			UpLoadFile upLoadFile = new UpLoadFile();
			upLoadFile.SaveInFoder = "/UpLoadFile/UserShop/";
			upLoadFile.NewFileName = newFileName;
			string text = upLoadFile.UploadPic(UploadPostFile, this.config, string.Empty);
			if (text == string.Empty)
			{
				this.WriteErrMsg("", Language.Get("Common/Fail", upLoadFile.ErrString), "");
			}
			result = text;
		}
		return result;
	}
}
